<?php 
require "DataLoad.php"; 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<?php CheckAdmin2();?>

<html>
<head>
<title><?php echo $GuildName;?> - DKP系统</title>
<script language="JavaScript" src="inc/jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="Generator" content="EditPlus">
<meta name="Author" content="SULei">
<meta name="Keywords" content="DKP WOW GUILD">
<meta name="Description" content="">
<link href="<?php echo $StylePath;?>/main.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" src="<?php echo $StylePath;?>/styleplus.js"></script>
<style type="text/css" media="all">
	td {font-family:;}
</style>

<!DOCTYPE html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title> New Document </title>
<script language="JavaScript" src="inc/jquery.js"></script>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="SULei">
<meta name="Keywords" content="">
<meta name="Description" content="">
<style type="text/css" media="all">

</style>
</head>

<body>

</body>
</html>
</head>

<body>
<?php 

switch (${"Action"}) {
	case "Form":
ImportForm();
		break;
	case "Post":
//有表单数据就覆盖旧缓存文件
		if (!($_POST["xmltext"]=="")) {

WriteFile("Renew.xml",$_POST["xmltext"]);
		} 

//建立DOM对象
		// $rXML is of type "MSXML.DOMDocument"
		$rXML->load$DOCUMENT_ROOT."xml/Renew.xml";
		$rtXML=$rXML->documentelement;

//建立DOM对象B
		// $sXML is of type "MSXML.DOMDocument"
		$sXML->load$DOCUMENT_ROOT."xml/Renew.xml";
		$stXML=$sXML->documentelement;

		if (!isset($rXML->getElementsByTagName("Leave")(0)->$childNodes) || !isset($rXML->getElementsByTagName("Loot")(0)->$childNodes) || !isset($rXML->getElementsByTagName("Join")(0)->$childNodes)) {

			print "数据不完整,无法进行处理. 可能是由于缺少拾取物品或离开人员的有关信息.";
		}
			else
		{

			$playerXML=$rXML->getElementsByTagName;      $childNodes;
			$leaveplayerXML=$rXML->getElementsByTagName;      $childNodes;
			$LootXML=$rXML->getElementsByTagName;      $childNodes;

			$playerXMLs=$sXML->getElementsByTagName;      $childNodes;

ImportPost();
			print "<h3>数据已经自动导入,请在确认无误后报告结果.</h3>";
			print "<h3 id='menu'><a href=''>活动</a> - <a href='admin_report.php?action=collect&id=".$RaidID."'>人员</a> - <a href='admin_report.php?action=collect2&id=".$RaidID."'>事件</a> - <a href='raid_report.php?id=".$RaidID."'>报告</a></h3>";
		} 

		break;
	default:

ImportMenu();
		break;
} 
?>


<?php 
function ImportMenu() {
	extract($GLOBALS);

	print "<a href='?Action=Form'>数据恢复</a>";
	print " | <a href='?Action=Post'>查看分析结果</a>";
	return $function_ret;
} 

function ImportForm() {
	extract($GLOBALS);

	print "<form method='post' action='?Action=Post'>粘贴要恢复的备份数据.<br/>";
	print "	<textarea name='xmltext' rows='30' cols='80'></textarea>";
	print "	<input type='submit' value='提交处理' />";
	print "<br>系统会缓存最近一次提交的数据到 xml/Renew.xml 文件中";
	print "</form>";
	return $function_ret;
} 








?>
</body>
</html>


<?php 
function ImportPost() {
	extract($GLOBALS);

	print "<h1>活动主题: ".$rtXML->childNodes->$item[1]->$text."</h1>";


	print is_object($rXML->getElementsByTagName("Loot")(0)->$childNodes);

//Response.write "<h2>Time:( "&DateE2C(rtXML.childNodes.item(0).text)&" - "&CDate(DateE2C(rtXML.childNodes.item(3).lastchild.childNodes.item(1).text))&" )</h2>"&vbCrlf
//调用方法
CTRT_Player();
CTRT_Leave();
CTRT_Loot();
FSDKP_Event();
	return $function_ret;
} 




function CTRT_Player() {
	extract($GLOBALS);
//参与相关处理|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
	print "<table class='dkplist'>"."\r\n";
	print "<tr><th colspan='6'>Raid Player List</th></tr>"."\r\n";
	print "<tr><th>Number</th><th>Name</th><th>Race</th><th>Class</th><th>Level</th><th>JoinTime</th></tr>"."\r\n";
//-----------------清理玩家表中重复的和信息不全的条目
	$ChildrenCount=$rtXML->childNodes->$item[2]->$childNodes->length-1;
	$arrPlayerList=",";
	for ($i=0; $i<=$ChildrenCount; $i=$i+1) {
		if ($playerXML->item($i)$childNodes->length<5) {

			$rtXML->childNodes->$item[2]->$removeChild[$playerXML->item($i)];
			$ChildrenCount=$ChildrenCount-1;
			$i=$i-1;
		}
			else
		{

			if ((strpos($arrPlayerList,",".$playerXML->item($i).$childNodes->item(0).$text.",") ? strpos($arrPlayerList,",".$playerXML->item($i).$childNodes->item(0).$text.",")+1 : 0)>0) {

				$rtXML->childNodes->$item[2]->$removeChild[$playerXML->item($i)];
				$ChildrenCount=$ChildrenCount-1;
				$i=$i-1;
			}
				else
			{

				$arrPlayerList=",".$playerXML->item($i)->$childNodes->item(0)->$text.$arrPlayerList;
			} 

		} 

		if ($i==$ChildrenCount) {
			break;

		} 

	}

//-----------------清理结束
//@@@@@@@@@@建立Raid 或修改已有的Raid信息
	$sql="select * from raid where raid_concentratetime=#".$CDate[$rtXML->childNodes->$item[0]->$text]."#";
	$result = mysql_query($sql);$sql  $conn
	if ($result->eof || $result->bof) {

		$result->close;
		$sql="select * from raid where (id is null)";
		$result = mysql_query($sql);$sql    $conn
		$result->addnew;
		$result["raid_name"]=$rtXML->childNodes->$item[1]->$text;
		$result["raid_concentratetime"]=$CDate[$rtXML->childNodes->$item[0]->$text];
		$result["raid_actiontime"]=$CDate[$rtXML->childNodes->$item[0]->$text];
		$result["raid_endtime"]=$CDate[$rXML->getElementsByTagName("Extra")(0)->$getElementsByTagName["Endtime"](0)->$text];
		$result["raid_personnel"]=40;
		$result["raid_class"]=1;
		$result["raid_player"]="";
		if ($result["raid_step"]==0) {

			$result["raid_step"]=1;
			$result["raid_ruler"]=1;
		} 

		$result->update;
//	response.write "添加新记录"
	}
		else
	{

		$RaidID=$result["id"];
		$result["raid_name"]=$rtXML->childNodes->$item[1]->$text;
//rs("raid_concentratetime")=CDate(DateE2C(rtXML.childNodes.item(0).text))
//rs("raid_actiontime")=DateAdd("n",30,CDate(DateE2C(rtXML.childNodes.item(0).text)))
//rs("raid_endtime")=CDate(DateE2C(rtXML.childNodes.item(3).lastchild.childNodes.item(1).text))
		if ($result["raid_step"]==0) {

			$result["raid_step"]=1;
		} 

		$result["raid_ruler"]=1;
		$result->update;
//	response.write "修改存在记录"
	} 

	$result->close;

//取得RaidID
	$sql="select * from raid where raid_concentratetime=#".$CDate[$rtXML->childNodes->$item[0]->$text]."#";
	$result = mysql_query($sql);$sql  $conn
	$RaidID=$result["id"];
	$RaidEndTime=$result["raid_endtime"];
	$result->close;

//删除此Raid全部事件,重新计算
	$sql="Delete * from raid_event where event_raidid=".$RaidID;
	$conn->execute($sql);


	$sql="Select * from raid_event where (id is null)";
	mysql_query($result2);
	$ChildrenCount=$rtXML->childNodes->$item[2]->$childNodes->length-1;
	for ($i=0; $i<=$ChildrenCount; $i=$i+1) {
//		if not (playerXML.item(i).childNodes.length<5)  then

		$playerName=$playerXML->item($i)->$childNodes->item(0)->$text;
		$playerRace=$playerXML->item($i)->$childNodes->item(1)->$text;
		$playerClass=$playerXML->item($i)->$childNodes->item(2)->$text;
		$playerLevel=$playerXML->item($i)->$childNodes->item(3)->$text;
		$playerJoinTime=$playerXML->item($i)->$childNodes->item(4)->$text;

//有表单数据就覆盖旧缓存文件
		if (!($_POST["xmltext"]=="")) {

WriteFile("CTRT_".time_type($playerJoinTime,3).".xml",$_POST["xmltext"]);
		} 


		print "<tr class='".linec($i)."'><td>".$i+1."</td><td>".$playerName."</td><td>".$playerRace."</td>";
		print "<td>".$ClassConvert[$playerClass]."</td><td>".$playerLevel."</td><td>".$playerJoinTime."</td></tr>"."\r\n";

//@@@@@@@@@@@@@
		$sql="select * from player where player_name='".$playerName."'";
		$result = mysql_query($sql);$sql    $conn
		if ($result->eof || $result->bof) {

			$result->close;
			$sql="select * from player where (id is null)";
			$result = mysql_query($sql);$sql      $conn
			$result->addnew;
			$result["player_name"]=$playerName;
			$result["player_level"]=$playerLevel;
			$result["player_race"]=$playerRace;
			$result["player_class"]=$ClassConvert[$playerClass];
			$result["player_honor"]="无";
			$result["player_jointime"]=$DateValue[$rtXML->childNodes->$item[0]->$text];
			$result["player_BaseDKP"]=0;
			$result["player_DKP"]=0;
			$result["player_skill_1"]="未知";
			$result["player_skill_2"]="未知";
			$result->update;
//					response.write "职业:"&ClassConvert(playerClass)
//				response.write "<br>添加新成员: "&playerName	
		}
			else
		{

			if ($result["player_level"]!=$playerLevel || $result["player_race"]!=$playerRace || $result["player_class"]!=$ClassConvert[$playerClass]) {

				$result["player_name"]=$playerName;
//						rs("player_level")=playerLevel
				$result["player_race"]=$playerRace;
				$result["player_class"]=$ClassConvert[$playerClass];
				$result->update;
//						response.write "<br>成员:"&playerName&" 的资料已更新"
			} 

		} 

		$result->close;

//++++++++++++ 成员加入事件写入
		if ($DateDiff["n"][$CDate[$playerJoinTime]][$DateAdd["n"][30][$CDate[$rtXML->childNodes->$item[0]->$text]]]<0) {

			$result2->addnew;
			$result2["event_raidid"]=$RaidID;
			$result2["event_time"]=$playerJoinTime;
			$result2["event_class"]="加入";
			$result2["event_dkp"]=0;
			$result2["event_object"]=name2id($playerName);
			$result2["event_object2"]="";
			$result2->update;
		} 


//		end if

	}

	$result2->close;

//****获取数据库中对应玩家ID
	$arrPlayerList=explode(",",substr(substr($arrPlayerList,0,strlen($arrPlayerList)-1),1));
	$sql="select * from player";
	$result = mysql_query($sql);$sql  $conn
	for ($i=1; $i<=$result->recordcount; $i=$i+1) {
		for ($j=0; $j<=count($arrPlayerList); $j=$j+1) {
			if ($result["player_name"]==$arrPlayerList[$j]) {

				$arrPlayerListNum[$j]=$result["id"];
			} 


		}

		$result->movenext;

	}

	$result->close;
//****
//&&&&添加成员
	$sql="select * from raid where id=".$RaidID;
	$result = mysql_query($sql);$sql  $conn
	$result["raid_player"]=$join[$arrPlayerListNum][", "];
	$result->update;
	$result->close;
//&&&&


	print "</table>"."\r\n";
	return $function_ret;
} 


function CTRT_Leave() {
	extract($GLOBALS);
//离开相关处理|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
	print "<table class='dkplist'>"."\r\n";
	print "<tr><th colspan='3'>Raid Leave List</th></tr>"."\r\n";

	print "<tr><th>Number</th><th>Name</th><th>最后离开时间</th></tr>"."\r\n";

// arrLeavePlayerList , arrLeavePlayerTime
//-----------------清理玩家离开表中重复的和信息不全的条目
	$ChildrenCount=$leaveplayerXML->length-1;
	$arrLeavePlayerList=",";
	$arrLeavePlayerTime=",";
	for ($i=0; $i<=$ChildrenCount; $i=$i+1) {
		$iz=$ChildrenCount-$i;
		if ($leaveplayerXML->item($iz)$childNodes->length<2) {

			$rtXML->childNodes->$item[3]->$removeChild[$leaveplayerXML->item($iz)];
			$ChildrenCount=$ChildrenCount-1;
			$i=$i-1;
		}
			else
		{

			if ((strpos($arrLeavePlayerList,",".$leaveplayerXML->item($iz).$childNodes->item(0).$text.",") ? strpos($arrLeavePlayerList,",".$leaveplayerXML->item($iz).$childNodes->item(0).$text.",")+1 : 0)>0) {

				$rtXML->childNodes->$item[3]->$removeChild[$leaveplayerXML->item($iz)];
				$ChildrenCount=$ChildrenCount-1;
				$i=$i-1;
			}
				else
			{

				$arrLeavePlayerList=",".$leaveplayerXML->item($iz)->$childNodes->item(0)->$text.$arrLeavePlayerList;
				$arrLeavePlayerTime=",".$leaveplayerXML->item($iz)->$childNodes->item(0)->$text.$arrLeavePlayerTime;
			} 

		} 

		if ($i==$ChildrenCount) {
			break;

		} 

	}

//-----------------清理结束
	$sql="Select * from raid_event where (id is null)";
	mysql_query($result2);
	$ChildrenCount=$leaveplayerXML->length-1;
	for ($i=0; $i<=$ChildrenCount; $i=$i+1) {
		if (!($leaveplayerXML->item($i)$childNodes->length<2)) {

			$leavePlayerName=$rtXML->childNodes->$item[3]->$childNodes->item($i)->$childNodes->item(0)->$text;
			$leavePlayerTime=$rtXML->childNodes->$item[3]->$childNodes->item($i)->$childNodes->item(1)->$text;
			print "<tr class='".linec($i)."'><td>".$i+1."</td><td>".$leavePlayerName."</td><td>".$leavePlayerTime."</td></tr>"."\r\n";

			if ($DateDiff["n"][$CDate[$leavePlayerTime]][$RaidEndTime]>5) {

				print "333".$leavePlayerName;
				if (CheckLeaveTime($leavePlayerName,$leavePlayerTime)) {

				  $result2->addnew;
				  $result2["event_raidid"]=$RaidID;
				  $result2["event_time"]=$leavePlayerTime;
				  $result2["event_class"]="离开";
				  $result2["event_dkp"]=0;
				  $result2["event_object"]=name2id($leavePlayerName);
				  $result2["event_object2"]="";
				  $result2->update;
				} 

			} 


		} 




	}

	$result2->close;

	print "</table>"."\r\n";

	return $function_ret;
} 


function CTRT_Loot() {
	extract($GLOBALS);
//物品相关处理|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
	print "<table class='dkplist'>"."\r\n";
	print "<tr><th colspan='8'>Raid Item Drop</th></tr>"."\r\n";
	print "<tr><th>Number</th><th>Item</th><th>ItemCode</th><th>Level</th><th>Count</th><th>Looter</th><th>LootTime</th><th>Note/DKP</th></tr>"."\r\n";
	$ChildrenCount=$rtXML->childNodes->$item[4]->$childNodes->length-1;

//^^^^^^^^^写入数据库
	$sql="Select * from raid_event where (id is null)";
	$result = mysql_query($sql);$sql  $conn

	for ($i=0; $i<=$ChildrenCount; $i=$i+1) {
		if (!($LootXML->item($i)$childNodes->length<7)) {

			$itemName=$LootXML->item($i)->$childNodes->item(0)->$text;
			$itemID=$LootXML->item($i)->$childNodes->item(1)->$text;
			$itemColor=$LootXML->item($i)->$childNodes->item(2)->$text;
			$itemCount=$LootXML->item($i)->$childNodes->item(3)->$text;
			$itemLooter=$LootXML->item($i)->$childNodes->item(4)->$text;
			$itemLootTime=$LootXML->item($i)->$childNodes->item(5)->$text;
			$itemNote=$LootXML->item($i)->$childNodes->item(6)->$text;
			print "<tr class='".linec($i)."'><td>".$i+1."</td><td>".$itemName."</td><td>".$itemID."</td><td>".$itemColor."</td>";
			print "<td>".$itemCount."</td><td>".$itemLooter."</td><td>".$itemLootTime."</td><td>".$itemNote."</td></tr>"."\r\n";

			$result->addnew;
			$result["event_raidid"]=$RaidID;
			$result["event_time"]=$itemLootTime;

			if (is_numeric($itemNote)) {

				$result["event_class"]="拾取";
				$result["event_dkp"]=intval($itemNote);
			}
				else
			if (strtoupper($itemNote)=="BOE") {

				$result["event_class"]="仓库";
				$result["event_dkp"]=40;
			}
				else
			if (strtoupper($itemNote)=="ENC") {

				$result["event_class"]="分解";
				$result["event_dkp"]=0;
			}
				else
			{

				$result["event_class"]="分解";
				$result["event_dkp"]=0;
			} 


			$result["event_object"]=name2id($itemLooter);
			$result["event_object2"]=$itemName;

			$result->update;

		} 


	}

	$result->close;
//^^^^^^^^^	


	print "</table>"."\r\n";


	return $function_ret;
} 


function FSDKP_Event() {
	extract($GLOBALS);
//处理Raid其他事件

	$EventXML=$rXML->getElementsByTagName;  $childNodes;

	$ChildrenCount=$EventXML->length-1;
//^^^^^^^^^RAID事件写入数据库
	$sql="Select * from raid_event where (id is null)";
	$result = mysql_query($sql);$sql  $conn
	for ($i=0; $i<=$ChildrenCount; $i=$i+1) {
		$Ex_EventClass=$EventXML->item($i)->$childNodes->item(0)->$text;
		$Ex_Player=$EventXML->item($i)->$childNodes->item(1)->$text;
		$Ex_Event=$EventXML->item($i)->$childNodes->item(2)->$text;
		$Ex_Time=$EventXML->item($i)->$childNodes->item(3)->$text;
		print "1";

		$result->addnew;
		$result["event_raidid"]=$RaidID;
		$result["event_time"]=$Ex_Time;
		$result["event_class"]=$Ex_EventClass;
		$result["event_object"]=$Ex_Player;
		$result["event_object2"]=$Ex_Event;
		$result->update;

	}

	$result->close;
//^^^^^^^^^	
	return $function_ret;
} 

function WriteFile($strFilename,$strFileText) {
	extract($GLOBALS);

	// $fso is of type "Scripting.FileSystemObject"
	$f=fopen($DOCUMENT_ROOT."xml/".$strFilename, "w");
	fputs($f,$strFileText."\n");
	fclose($f);
	$fso=null;

	return $function_ret;
} 

function DateE2C($d) {
	extract($GLOBALS);

	$arrD=explode("/",$d);
	$function_ret="20".substr($arrD[2],0,2)."-".$arrD[0]."-".$arrD[1]." ".substr($arrD[2],3);
	return $function_ret;
} 

function checkPR($n) {
	extract($GLOBALS);


	return $function_ret;
} 


function CheckLeaveTime($cname,$ctime) {
	extract($GLOBALS);

	$function_ret=true;
	$CCount=$stXML->childNodes->$item[2]->$childNodes->length-1;
//response.write "----------N:"&cname&" ----- T:"&ctime&"---------<br>"
	for ($ik=0; $ik<=$CCount; $ik=$ik+1) {
//if not (playerXMLs.item(ik).childNodes.length<5)  then
		if ($cname==$playerXMLs->item($ik)$getElementsByTagName["player"](0)$text && $DateDiff["n"][$CDate[$playerXMLs->item($ik)->$getElementsByTagName["time"](0)->$text]][$ctime]<0) {

//response.write cname&" - "&playerXMLs.item(ik).childNodes.item(0).text&"<BR>"
//response.write ctime&" - "&CDate(DateE2C(playerXMLs.item(ik).childNodes.item(4).text))&"| "
//response.write DateDiff("n",CDate(DateE2C(playerXMLs.item(ik).childNodes.item(4).text)),ctime)&"<BR>"

//	response.write "N:"&playerXMLs.item(ik).childNodes.item(0).text&" T:"&DateE2C(playerXMLs.item(ik).childNodes.item(4).text)&"<br>"
			$function_ret=false;
			return $function_ret;

		}
			else
		{

//	response.write ">>N:"&playerXMLs.item(ik).childNodes.item(0).text&" T:"&DateE2C(playerXMLs.item(ik).childNodes.item(4).text)&"<br>"
		} 

//end if

	}

	return $function_ret;
} 
?>
